<template>
  <div class="tabel_container">
    <el-table
      :data="tableData"
      :border="border"
      v-loading="loading"
      element-loading-text="拼命加载中"
      element-loading-background="rgba(0, 0, 0, 0.8)"
    >
      <template v-for="(item, index) in tableCols">
        <el-table-column
          :prop="item.prop"
          :label="item.label"
          :width="item.width"
          :align="align"
          v-if="!item.defined"
          :key="index"
        />
        <el-table-column
          v-if="item.defined"
          :label="item.label"
          :align="align"
          :key="index"
        >
          <template #default="scope">
            <!-- 按钮 -->
            <el-button
              :type="item.style"
              :size="item.size"
              v-if="item.option == 'button'"
              >{{ scope.row[item.prop] }}</el-button
            >
            <!-- tag标签 -->
            <el-tag
              :type="item.style || ''"
              :size="item.size || ''"
              v-if="item.option == 'tag'"
              >{{ scope.row[item.prop] }}</el-tag
            >
            <!-- 开关按钮 -->
            <el-switch
              v-if="item.option == 'switch'"
              v-model="scope.row[item.prop]"
              :inline-prompt="item.inlinePrompt"
              :active-value="1"
              :inactive-value="0"
              class="mb-2"
              :active-text="item.activeText"
              :inactive-text="item.inactiveText"
            >
            </el-switch>
            <!-- 默认格式 -->
            <div v-if="!item.option">{{ scope.row[item.prop] }}</div>
          </template>
        </el-table-column>
      </template>
      <!-- 操作的列表 -->
      <el-table-column
        :label="v.label"
        v-for="(v, i) in tabelOption"
        :key="`A+${i}`"
        :align="align"
      >
        <template slot-scope="scope">
          <el-button
            v-for="(d, t) in v.oper"
            :key="t"
            :size="d.size"
            :type="d.style"
            @click="handleButton(scope.row, d.clickFun)"
            >{{ d.name }}</el-button
          >
        </template>
      </el-table-column>
      <div slot="empty" class="emptyBg" v-show="!loading&&tableData.length==0">
        <img src="@/assets/empty/empty.png" alt="" />
        <p>暂无数据</p>
      </div>
    </el-table>
  </div>
</template>

<script>
export default {
  props: {
    tableData: {
      type: Array,
      defalut: [],
    },
    tabelOption: {
      type: Array,
      defalut: [],
    },
    border: {
      type: Boolean,
      defalut: false,
    },
    tableCols: {
      type: Array,
      defalut: [],
    },
    align: {
      type: String,
      defalut: "",
    },
    loading: {
      type: Boolean,
      defalut: false,
    },
  },
  data() {
    return {};
  },
  methods: {
    handleButton(row, method) {
      this.$emit("click", { row, method });
    },
  },
};
</script>
<style lang="scss" scoped>
.emptyBg {
  margin: 40px auto;
  img {
    width: 170px;
  }
}
</style>
